<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.infomanage.po.*" %>
<%@page import="com.infomanage.vo.*" %>
<%@page import="com.infomanage.enums.*"%>
<%@page import="com.infomanage.service.equmgmt.*"%>
<%
	request.setCharacterEncoding("UTF-8");
	String eqmtId = request.getParameter("eqmtId");
    if(eqmtId == null) eqmtId = "";
    
    EquipmentManageItem eqmt = EquipmentManageService.loadEquipmentManage(request, response, out);
    int personId = -1;
    String personName = "";
    int owndeptId = -1;
    String owndeptName = "";
    int usedeptId = -1;
    String usedeptName = "";
    String name = "";
    int quantity = 0;
    int status = -1;
    String type = "";
    String desc = "";
    String usage = "";
    if(eqmt != null) {
    	EquipmentManage equ = eqmt.getBean();
    	Person person = eqmt.getPerson();
	    Department ownDept = eqmt.getOwndept();
	    Department useDept = eqmt.getUsedept();
	    
    	personId = equ.getPersonId();
    	personName = person.getName();
    	owndeptId = ownDept.getDeptId();
    	owndeptName = ownDept.getName();
    	usedeptId = useDept.getDeptId();
    	usedeptName = useDept.getName();
	    name = eqmt.getBean().getName();
	    usage = equ.getPurpose();
	    status = equ.getState();
	    type = equ.getType();
	    quantity = equ.getQuantity();
	    desc = eqmt.getBean().getDescription();
    } 
%>
<html>
<head>
	<title>装备管理</title>
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<link href="../../css/calendar.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../../js/calendar.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript">
	 function init() {
		   if("" != "<%=eqmtId%>") { // 修改
			   form1.state.value = "<%=status%>";	
		   }
	   }
	   // 提交
	   function doSubmit(){
	   		if(validate()){
	   			return;
	   		}
		 	if("" == "<%=eqmtId%>") {
		 		form1.actionType.value = "add";
			}else {
		 		form1.actionType.value = "modify";
			}
		 	form1.submit();
	   }
	   
	   function validate(){
	   		if(form1.name.value == ""){
	   			alert("装备名称不能为空！");
	   			return true;
	   		}
	   		if(form1.owndeptId.value == -1){
	   			alert("所属单位不能为空！");
	   			return true;
	   		}
	   		if(form1.userdeptId.value == -1){
	   			alert("使用单位不能为空！");
	   			return true;
	   		}
	   		
	   		if(form1.personId.value == -1){
	   			alert("负责人不能为空！");
	   			return true;
	   		}
	   		
	   		if(isNaN(form1.quantity.value)){
	   			alert("数量必须位数字！");
	   			return true;
	   		}
	   		return false;
	   }

	   function showError(error){
		   alert(error);
	   }

	   function showInfo(info){
		   alert(info);
		   window.returnValue = "ok";
		   window.close();
	   }
	</script>
</head>
<body  rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0" onclick="clickBody();" onload="init();">
	<form name="form1" action="equmgmt_action.jsp" method="post" target="actionFrame">
	<input type="hidden" name="eqmtId" value="<%=eqmtId%>">
	<input type="hidden" name="actionType">
	<table class="dialogTable" cellpadding="0" cellspacing="0">
		<!-- 表头-->
		<tr class="dialogTableHeader">
			<td>装备管理</td>
		</tr>
		<!-- 表数据-->
		<tr class="dialogTableContent">
			<td>
				<!-- 数据项 -->
				<table class="dataTable">
					<col width="30%">
					<col width="70%">
					<tr>
						<td class="field">
							装备名称
						</td>
						<td>
							<input value="<%=name%>" name="name" style="width: 100%" type="text">
						</td>
					</tr>
					<tr>
						<td class="field">
							所属单位
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this,'../common/deptTree.jsp');" treeSelect="true">
								<input value="<%=owndeptName %>" style="width: 338px" readonly="readonly" treeSelect="true"><input name="owndeptId" value="<%=owndeptId %>" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td class="field">
							使用单位
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/deptTree.jsp');" treeSelect="true">
								<input value="<%=usedeptName %>" style="width: 338px" readonly="readonly" treeSelect="true"><input name="userdeptId" value="<%=usedeptId %>" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td class="field">
							负责人
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true">
								<input value="<%=personName %>" style="width: 338px" readonly="readonly" treeSelect="true"><input name="personId" value="<%=personId%>" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td  class="field">
							数量
						</td>
						<td>
							<input value="<%=quantity %>" style="width: 100%;" name="quantity">
						</td>
					</tr>
					<tr>
						<td class="field">
							型号
						</td>
						<td>
							<input value="<%=type %>" style="width: 100%;" name="type">
						</td>
					</tr>
					<tr>
						<td class="field">
							用途
						</td>
						<td>
							<input value="<%=usage%>" style="width: 100%;" name="usage">
						</td>
					</tr>
					<tr>
						<td class="field">
							状态
						</td>
						<td>
							<select style="width: 100%" name="state">
							   <%
			                   		for(DeviceStatusType statusType: DeviceStatusType.getMembers()){
			                   %>			
			                   		<option value="<%= statusType.value() %>"><%= statusType.title()%></option>
			                   <%
			                   		}
			                   %>
							</select>
						</td>
					</tr>
					<tr style="height: 100px">
						<td class="field">
							备注
						</td>
						<td valign="top">
							<textarea style="width: 100%;height: 100%" name="description"><%=desc%></textarea>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="tableBtn">
				<span onclick="doSubmit();">确定</span>
				<span onclick="window.close();">取消</span>
			</td>
		</tr>
		<tr valign="top">
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
	</table>
	<iframe src="#" frameborder="0" id="treeFrame" name="frame" style="display: none;position: absolute;"></iframe>
	<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</body>
</html>